package net.sareweb.acab.actions.request;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.faces.event.ActionEvent;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.framework.EntityQuery;
import org.jboss.seam.jsf.ListDataModel;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;

import net.sareweb.acab.actions.generic.BasicBean;
import net.sareweb.acab.annotations.SearchComponent;
import net.sareweb.acab.entity.Request;
import net.sareweb.acab.entity.Suggestion;
import net.sareweb.acab.entity.User;
import net.sareweb.acab.entity.manager.RequestManager;

@Name("requestBean")
@Scope(ScopeType.CONVERSATION)
public class RequestBean {
	
	@Logger
	private Log log;
	@In 
	Credentials credentials;

	Request request;
	@In(create=true)
	RequestManager requestManager;
	
	/*@DataModel
	ListDataModel suggestions;*/
	
	private Integer idRequest; 
	
	
	public String  loadRequestAction(){
		log.debug("loadRequestAction, idRequest value = {0}", idRequest);
		if(idRequest==null || "".equals(idRequest)) return "error";
		request=(Request) requestManager.find(idRequest);
		return "";
	}
	
	public List<Suggestion> getSuggestions() {
		return request.getSuggestions() == null ? null : new ArrayList<Suggestion>(
				request.getSuggestions());
	}
	
	
	@Begin
	public String start(){
		return "/acab/request/MyRequest.xhtml";
	}
	
	@End
	public String end(){
		return "/home.xhtml";
	}

	public Integer getIdRequest() {
		return idRequest;
	}

	public void setIdRequest(Integer idRequest) {
		this.idRequest = idRequest;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}
	
	
	
}
